﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XuanXiang.Api.Admin.Filters;
using XuanXiang.Infrastructure.Attr;
using XuanXiang.Infrastructure.Dto.Request;
using XuanXiang.Service.Interface;

namespace XuanXiang.Api.Admin.Controllers
{
    [ApiGroup("Admin(管理员模块)")]
    public class LogsController : BaseController
    {
        private readonly I_Log_Service _log_service;

        public LogsController(I_Login_Service login_Service,I_Log_Service log_service) : base(login_Service)
        {
            _log_service = log_service;
        }

        /// <summary>
        /// 获取所有的错误日志
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Error_Log(int page = 1, int limit = 10) {
            var reslut = await _log_service.Get_Error_Log(new Fenye_Dto() { 
            page=page,
            limit=limit
            });
            return Ok(reslut);
        }

        /// <summary>
        /// 获取登录日志
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="account"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        [Authorize(Roles = "admin")]
        
        public async Task<IActionResult> Get_Login_Log(int page=1,int limit=10,string? account="",string? name="") 
        {
            var result = await _log_service.Get_Login_Log(new Fenye_Dto() { 
            page=page,
            limit=limit,
            account=account,
            name=name
            });

            return Ok(result);  
        }

        /// <summary>
        /// 获取所有的操作日志
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public async Task<IActionResult> Get_Action_Logs(int page=1,int limit=10,string? account="",string? name="") {
           
            var result = await _log_service.Get_Active_Logs(new Fenye_Dto() { 
            page=page,
            limit=limit,
            name=name,
            account=account

            });
            return Ok(result);
        
        }
    }
}
